package com.baosight.sczx.zm.cc.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.StaticBlocks;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.cInterface.Department;
import com.baosight.sczx.common.zm.cInterface.cs.InitialData;
import com.baosight.sczx.zm.cc.domain.ZMCCProduceproblem;
import com.baosight.sczx.zm.cc.domain.ZMCCProduceproblemHandleProcess_x;

/**
 * 
 * <p>Title: ServiceZMCC21.java</p>
 * <p>Description: 生产问题整改反馈模块 生产问题责任 部门操作 已整改生产问题</p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 郭淑芳
 * @version 1.0
 * <pre>Histroy:
 *          2016年9月28日 下午1:53:28  郭淑芳  Create
 *</pre>
 */
public class ServiceZMCC21 extends ServiceEPBase {

	/**
	 * 
	 * <p>Function: initLoad</p>
	 * <p>Description: 初始化进入</p>
	 * <p>return value: ServiceZMCC21</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月28日下午1:53:15 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");// 如果不加这个，翻页的统计和显示是错误的
		EiInfo outInfo = this.query(inInfo);

		return outInfo;
	}

	/**
	 * 
	 * <p>Function: query</p>
	 * <p>Description: 查询</p>
	 * <p>return value: ServiceZMCC21</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2016年9月28日下午1:53:36 郭淑芳
	 * </p>
	 *
	 */
	@Override
	public EiInfo query(EiInfo inInfo) {

		EiInfo outInfo = new EiInfo();
		EiBlock resultBlock = new EiBlock("result");
		ZMCCProduceproblemHandleProcess_x _dom = new ZMCCProduceproblemHandleProcess_x();
		resultBlock.addBlockMeta(_dom.eiMetadata);
		Map<String, String> _args = new HashMap<String, String>();
		if (inInfo.getBlock(EiConstant.queryBlock) == null) {
			_args.put("fdEndDate", StaticTools.getDate());// 截止日期
		}
		_args.put("isModifyed", "yes"); // 所有已整改隐患
		_args.put("fdMiningId", UserSession.getInSessionProperty("miningCode").toString());
		_args.put("fdBusinessDepartmentId", UserSession.getInSessionProperty("orgCode").toString());

		List<ZMCCProduceproblem> _result = dao.query("ZMCCProduceproblem.query", _args);
		for (int i = 0; i < _result.size(); i++) {
			ZMCCProduceproblem record = (ZMCCProduceproblem) _result.get(i);
			Map<String, String> process_args = new HashMap<String, String>();
			process_args.put("fdRecordId", record.getFdKeyId());
			List<ZMCCProduceproblemHandleProcess_x> process_result = dao.query("ZMCCProduceproblemHandleProcess_x.query", process_args);
			resultBlock.addRows(process_result);
		}
		outInfo.addBlock(resultBlock);
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cp.problemType", false));// 问题类型
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cp.problemLevel", false));// 问题级别
		outInfo.addBlock(StaticBlocks.getBlockData("cmes.cp.problemStatus", new String[]{"0", "1", "2", "3", "4", "5", "6"}, new String[]{"草拟", "未处理", "未查收", "未整改", "未核查", "关闭", "作废"}, true));//问题状态
		outInfo.addBlock(StaticBlocks.getBlockData("cmes.cp.isCheck", new String[] { "否", "是" }, new String[] { "否", "是" }, true));// 是否重复问题
		outInfo.addBlock(InitialData.getInstance().getEiBlockByNo("cmes.cp.problemOrigin"));// 问题来源
		outInfo.addBlock(Department.getInstance().getConstructionUnit("cmes.cp.department", "orgCode", "orgName", false));
		return outInfo;
	}
}
